package com.ldc.wandroid.adapter;

import android.widget.CheckBox;

import androidx.annotation.NonNull;

import com.ldc.common.common.CommonRecyclerView;
import com.ldc.common.common.CommonRecyclerViewHolder;
import com.ldc.common.common.CommonViewClick;
import com.ldc.common.utils.TimeUtils;
import com.ldc.wandroid.R;
import com.ldc.wandroid.model.ArticleModel;

import java.sql.Date;

public class SystemInfoAdapter extends CommonRecyclerView<ArticleModel.DatasBean> {


    private CommonViewClick<ArticleModel.DatasBean> itemClick, itemCollection;

    public SystemInfoAdapter() {
        super(R.layout.layout_item_system_info);
    }


    public void addRowClick(CommonViewClick<ArticleModel.DatasBean> itemClick) {
        this.itemClick = itemClick;
    }

    public void addRowCollectionClick(CommonViewClick<ArticleModel.DatasBean> itemClick) {
        this.itemCollection = itemClick;
    }

    @Override
    protected void convert2Data(@NonNull CommonRecyclerViewHolder baseViewHolder, ArticleModel.DatasBean bean, int position) {
        baseViewHolder.setText(R.id.tv_title, String.format("%s•%s", bean.getSuperChapterName(), bean.getChapterName()));
        baseViewHolder.setText(R.id.tv_context, String.format("%s", bean.getTitle()));
        baseViewHolder.setText(R.id.tv_author, String.format("%s", bean.getAuthor()));
        baseViewHolder.setText(R.id.tv_time, String.format("%s", TimeUtils.date2String(new Date(bean.getPublishTime()), "yyyy/MM/dd")));
        ((CheckBox) baseViewHolder.findViewById(R.id.ck_collect)).setChecked(bean.isCollect());
        baseViewHolder.findViewById(R.id.ck_collect).setOnClickListener(v -> {
            if (itemCollection != null) {
                itemCollection.onRow(bean);
            }
        });
        baseViewHolder.itemView.setOnClickListener(v -> {
            if (null != itemClick) {
                itemClick.onRow(bean);
            }
        });


    }
}
